package cn.bonoon.kernel.web.html.form;

import cn.bonoon.handler.AutoManager;
import cn.bonoon.kernel.descriptors.UIClassDescriptor;
import cn.bonoon.kernel.descriptors.UIPropertyAccessor;
import cn.bonoon.kernel.web.annotations.form.FormUpdate;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyUpdate;

public final class StandardUpdateBuilder extends AbstractEditableBuilder{
	
	public StandardUpdateBuilder(UIClassDescriptor uiDescriptor, AutoManager manager) {
		super(uiDescriptor, manager);
	}
	
	@Override
	protected void init() {
		super.init();
		FormUpdate fd = uiDescriptor.getAnnotation(FormUpdate.class);
		if(null != fd){
			if(fd.value() > 0){
				column= fd.value();
			}
			if(fd.headWidth() > 0){
				headWidth = fd.headWidth();
			}
			if(fd.width() > 0){
				propertyWidth = fd.width();
			}
			if(!fd.formStyleClass().isEmpty()){
				tableClass = fd.formStyleClass();
			}
		}
	}
	
	@Override
	protected PropertyEditParser readProperty(UIPropertyAccessor descriptor) {
		PropertyEditor pe = descriptor.getAnnotation(PropertyEditor.class);
		if (null != pe && pe.ignoreModify()) return null;
		PropertyUpdate pm = descriptor.getAnnotation(PropertyUpdate.class);
		if (null == pe && null == pm) return null;
		return new PropertyEditParser(this, descriptor, pe, pm);
	}
}
